<!-- 项目管理 -->
<template>
  <div class="page-box h100 display-flex czbj" v-if="ifsd">
    <p class="title-label mb10">检测列表</p>
    <!-- sonRouter="yybureauFormationBJ" 为跳转新的页面编辑 -->
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :ispiliang="true"
      :czFun="czFun"
      :qx="qx"
      ref="databale"
    ></dxtable>
  </div>
</template>
<script lang="ts" setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost, prefixS, downImg } from "../../util/index";
import { NButton, NImage, NTag } from "naive-ui";
import { h, ref, reactive } from "vue";
const databale = ref();
const ifsd = ref(false);
const initeer = () => {
  databale.value.initDataExpose();
};
function formatNumber(num) {
  // 检查当前数字在50000到60000范围还是在60000之后
  if (num >= 50000 && num < 60000) {
    return String(num - 49999).padStart(4, "0"); // 显示从0001到10000
  }
  if (num >= 60000 && num < 70000) {
    return String(num - 59999).padStart(4, "0"); // 显示从0001到10000
  }
  if (num >= 70000 && num < 80000) {
    return String(num - 69999).padStart(4, "0"); // 显示从0001到10000
  } 
  
  if (num >= 80000) {
    return String(num - 79999).padStart(4, "0"); // 显示从0001开始
  }
}
const xmlxSelect = ref();
let dataJson = [
  {
    title: "id",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    width: 100,
    span: 12,
    key: "id",
  },
  {
    title: "报告编号",
    type: "select",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "reportNo",
    width: "",
    search: true,
    istable: true,
    required: true,
    render: (row) => {
      try {
        return xmlxSelect.value.filter((a) => row.reportNo == a.value)[0].label;
      } catch (e) {
        return "-";
      }
    },
  },
  {
    title: "板料编号",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "plateNumber",
    width: "",
    // "search": true,
    istable: true,
    required: true,
    render: (row) => {
      let ksdr = (row.id % 10000) - 100;
      return row.plateNumber + formatNumber(row.id);
      if (ksdr < 0) {
        return row.plateNumber + formatNumber(row.id);
      } else {
        return row.plateNumber + ksdr;
      }
    },
  },
  {
    title: "名称",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "name",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "含量",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "content",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "质量",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "weight",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  ,
  // {
  //   "title": "检测报告",
  //   "type": "imglist",
  //   "val": [],
  //   render: (row) => {
  //     try{
  //       row.bgImageList = row.bgImageList.split(",")
  //     }catch(e){

  //     }
  //     return h(NImage,{src:row.bgImageList[row.bgImageList.length-1],class:"dxvgdftrytry"})
  //   }
  // }
  //  {
  //   title: "排序",
  //   width: 100,
  //   render: (row) => {
  //     row.sjk = "jcbg" //数据库
  //     row.databaseName = "keyEnterprise"; //表名
  //     return h(sort, {
  //       row,
  //       onCallBack: () => {
  //         initeer();
  //       },
  //     });
  //   },
  // },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "gjxindexdel", //删除
  EditPermissionIdentifier: "gjxindexbj", // 编辑
  NewPermissionIdentifier: "gjxindexxz", // 新建
  ViewPermissionID: "gjxindexck", // 查看
};
const portUrl = "gjx/jcbg";

let formJson = reactive([
  {
    title: "报告编号",
    type: "select",
    options: [],
    val: "1",
    icon: "dx-shurukuang",
    span: 24,
    key: "reportNo",
    width: "",
    search: true,
    istable: true,
  },
  {
    title: "板料编号",
    type: "input",
    val: "FTJ250",
    icon: "dx-shurukuang",
    span: 12,
    key: "plateNumber",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "名称",
    type: "input",
    val: "金锭",
    icon: "dx-shurukuang",
    span: 12,
    key: "name",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "含量",
    type: "input",
    val: "金含量:99.995%",
    icon: "dx-shurukuang",
    span: 12,
    key: "content",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "质量",
    type: "input",
    val: "1000g",
    icon: "dx-shurukuang",
    span: 12,
    key: "weight",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  // {
  //   "title": "检测报告",
  //   "type": "imglist",
  //   "val": [],
  //   "icon": "dx-ai-img-list",
  //   "span": 12,
  //   "key": "bgImageList",
  //   "width": "",
  //   "search": false,
  //   "istable": true,
  //   "required": false
  // }
]);
const fsdsd = ref(false);
const czFun = {
  fun: (row) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          loading: fsdsd.value,
          onClick: async (e) => {
            navigator.clipboard.writeText(
              "https://duxinggj.com/j/index.html#/?id=" + row.id
            );
            window.$message.success("复制成功！");
            // let jnjxdf = row.qccode
            // fsdsd.value = true
            // if(!row.qccode){
            //   const {data}  = await dxget("public/QRcode/clt",{
            //     text:'https://duxinggj.com/j/?id='+row.id
            //   })
            //   jnjxdf = data
            //   await dxpost(portUrl,{id:row.id,qccode:data},"put")
            //   initeer()
            // }

            //  await downImg(jnjxdf,row.reportNo,".svg")
            //  fsdsd.value = false
          },
        },
        "复制链接"
      ),
    ];
  },
};

// 获取字典内容
const xtgxxmfl = async () => {
  const { data }: any = await dxget("gjx/api/jjnmxcz", "");
  dataJson[0].options = [
    {
      label: "全部",
      value: "",
    },
    ...data,
  ];
  formJson[0].options = data;

  formJson[0].val = data[0].value;
  xmlxSelect.value = data;
   let jdfdsf = new Date()
   let kjfdsf = jdfdsf.getMonth()+1
   let jdfdzesf = jdfdsf.getDate()
   jdfdzesf = jdfdzesf<10?('0'+jdfdzesf):jdfdzesf



  formJson[1].val = 'FTJ250'+ kjfdsf+jdfdzesf
  ifsd.value = true;
};
xtgxxmfl();
</script>
<style scoped></style>
